#! /bin/bash
if [ "$1" == "stop" ]; then
echo "stop servers"
name="./server"
ps aux | grep $name | grep -v grep | awk '{print $2}' | while read pidnumber
do
kill -9 $pidnumber
done
exit
fi

if [ "$2" != "start" ]; then
echo "wrong input"
exit
fi
numofserver=$1
if [ "$numofserver" -gt "11" ]; then
echo "numofserver cannot be larger than 11"
exit
elif [ "$numofserver" -lt "3" ]; then
echo "numofserver cannot be smaller than 3"
exit
fi

index=1
while [ "$index" -le "$numofserver" ]
do
temp=$(($index +8009))
./server $temp &
index=$(($index +1))
done
